package com.ruoyi.project.data.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.service.PermissionService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.data.domain.WaybillAlarmInformation;
import com.ruoyi.project.data.service.IWaybillAlarmInformationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 运单报警信息Controller
 *
 * @author ruoyi
 * @date 2020-04-27
 */
@RestController
@RequestMapping("/data/information")
public class WaybillAlarmInformationController extends BaseController
{
    @Autowired
    private IWaybillAlarmInformationService waybillAlarmInformationService;
    @Autowired
    private PermissionService permissionService;

    /**
     * 查询运单报警信息列表
     */
//    @PreAuthorize("@ss.hasPermi('data:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaybillAlarmInformation waybillAlarmInformation)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        waybillAlarmInformation.setRole(user.getRoles().get(0).getRoleKey());
        // 场站id
        Long stationId = user.getStationId();
        waybillAlarmInformation.setStationId(stationId);
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        waybillAlarmInformation.setAreas(areas);
        waybillAlarmInformation.setManagementCharacters(managementCharacters);
        startPage();
        List<WaybillAlarmInformation> list = waybillAlarmInformationService.selectWaybillAlarmInformationList(waybillAlarmInformation);
        return getDataTable(list);
    }

    /**
     * 导出运单报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('data:information:export')")
    @Log(title = "运单报警信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WaybillAlarmInformation waybillAlarmInformation)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        // 场站id
        Long stationId = user.getStationId();
        waybillAlarmInformation.setStationId(stationId);
        // 管辖区域
        List<String> areaList = user.getAreaList();
        String areas = String.join(",", areaList);
        String managementCharacters = user.getManagementCharacters();
        waybillAlarmInformation.setAreas(areas);
        waybillAlarmInformation.setManagementCharacters(managementCharacters);
        List<WaybillAlarmInformation> list = waybillAlarmInformationService.selectWaybillAlarmInformationList(waybillAlarmInformation);
        ExcelUtil<WaybillAlarmInformation> util = new ExcelUtil<WaybillAlarmInformation>(WaybillAlarmInformation.class);
        return util.exportExcel(list, "information");
    }

    /**
     * 获取运单报警信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('data:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(waybillAlarmInformationService.selectWaybillAlarmInformationById(id));
    }

    /**
     * 新增运单报警信息
     */
    @PreAuthorize("@ss.hasPermi('data:information:add')")
    @Log(title = "运单报警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaybillAlarmInformation waybillAlarmInformation)
    {
        return toAjax(waybillAlarmInformationService.insertWaybillAlarmInformation(waybillAlarmInformation));
    }

    /**
     * 修改运单报警信息
     */
//    @PreAuthorize("@ss.hasPermi('data:information:edit')")
    @Log(title = "运单报警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaybillAlarmInformation waybillAlarmInformation)
    {
        return toAjax(waybillAlarmInformationService.updateWaybillAlarmInformation(waybillAlarmInformation));
    }

    /**
     * 删除运单报警信息
     */
    @PreAuthorize("@ss.hasPermi('data:information:remove')")
    @Log(title = "运单报警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waybillAlarmInformationService.deleteWaybillAlarmInformationByIds(ids));
    }
}
